<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;

class Index extends Base
{
    public function index()
    {
        return $this->fetch();
    }

    public function welcome()
    {

        $data['register'] = Db:: table('ad_user')->count('id');
        $data['userinc']  = Db::table('ad_user_info')->whereTime('register_time', 'today')->count('uid');
        $data['active']   = Db::table('ad_user')->whereTime('last_login', 'today')->count('id');
        $data['adsinc']   = Db::table('ad_list')->whereTime('create_time', 'today')->count('id');
        $data['share']    = Db::table('ad_fx')->whereTime('create_time', 'today')->count('id');

        //广告主数量 adv    自媒体数量 media    有效广告主数量 validadv   有效自媒体数量 validmedia
        $data['adv']       = Db::table('ad_user_info')->where('type', 1)->count('uid');
        $data['media']     = Db::table('ad_user_info')->where('type', 2)->count('uid');
        $data['validadv']  = Db::table('ad_banner_money')
            ->alias('m')
            ->join('ad_user_info u', 'm.uid = u.uid')
            ->where(['u.type' => 1])
            ->group('u.uid')
            ->count('u.uid');
        $data['valimedia'] = Db::table('ad_banner_money')
            ->alias('m')
            ->join('ad_user_info u', 'm.uid = u.uid')
            ->where(['u.type' => 2])
            ->group('u.uid')
            ->count('u.uid');
        return view('welcome', compact('data'));
    }

    public function getRole()
    {
        $role = session('url', '', 'admin');
        dump($role);
//        //获取session里的roleid
//        $role = session('roleId', '', 'admin');
//        //到权限表读取栏目id
//        $pri_info = model('Pri')->where('column_id ='.$role)->find();
//        //到栏目表里读取栏目信息
//        $column_info = model('Column')->where('id = '.$pri_info['column_id'])->find();
//
//        $column_list = model('Column')->where('pid = 0')->select();
//        return json($column_list);
    }
}
